package org.kessy.common.model.meta;

import java.util.ArrayList;
import java.util.Collection;

/***
 * 
 * @author leo.liu
 * Meta Entity, represent an type of object
 */
public class MEntity extends MBase{

    /**
     * 
     */
    private static final long serialVersionUID = 7238450025602936323L;

    private String name;
    private String label;
    private String tableName;
    private String fieldEid;
    private String eidSeq;
    private String entityType; // singleDictionary meta, rule, service
    // private MEntity parentEntity; 
    private Collection<MAttribute> attributes;
    private Collection<MRelation> relations;
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getLabel() {
        return label;
    }
    
    public void setLabel(String label) {
        this.label = label;
    }
    
    public String getTableName() {
        return tableName;
    }
    
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
    
    public String getFieldEid() {
        return fieldEid;
    }
    
    public void setFieldEid(String fieldEid) {
        this.fieldEid = fieldEid;
    }
    
    public String getEidSeq() {
        return eidSeq;
    }
    
    public void setEidSeq(String eidSeq) {
        this.eidSeq = eidSeq;
    }
    
    public String getEntityType() {
        return entityType;
    }
    
    public void setEntityType(String entityType) {
        this.entityType = entityType;
    }
    
//    public MEntity getParentEntity() {
//        return parentEntity;
//    }
//
//    public void setParentEntity(MEntity parentEntity) {
//        this.parentEntity = parentEntity;
//    }

    public Collection<MAttribute> getAttributes() {
        return attributes;
    }
    
    public void setAttributes(Collection<MAttribute> attributes) {
        this.attributes = attributes;
    }
    
    public void addAttribute(MAttribute _mAttribute){
        if(_mAttribute == null)
            return;
        
        if(attributes == null)
            attributes = new ArrayList<MAttribute>();
        
        attributes.add(_mAttribute);
    }
    
    public void removeAttribute(MAttribute _mAttribute){
        if(_mAttribute == null)
            return;
        
        if(attributes != null)
            attributes.remove(_mAttribute);
    }
    
    public Collection<MRelation> getRelations() {
        return relations;
    }
    
    public void setRelations(Collection<MRelation> relations) {
        this.relations = relations;
    }
    
    public void addRelation(MRelation _mRelation){
        if(_mRelation == null)
            return;
        
        if(relations == null)
            relations = new ArrayList<MRelation>();
        
        relations.add(_mRelation);
    }
    
    public void removeRelation(MRelation _mRelation){
        if(_mRelation == null)
            return;
        
        if(relations != null)
            relations.remove(_mRelation);
    }
    
    @Override
    public void copyShallow(MBase mBase) {
        super.copyShallow(mBase);
        
        MEntity mEntity = (MEntity)mBase;
        
        this.name = mEntity.getName();
        this.label = mEntity.getLabel();
        this.tableName = mEntity.getTableName();
        this.fieldEid = mEntity.getFieldEid();
        this.eidSeq = mEntity.getEidSeq();
        this.entityType = mEntity.getEntityType();
    }
}
